<!--   
Persistent Digital Archives and Library System (PeDALS) 
(c) 2008 - All Rights Reserved
//-->
<?php 
include 'includes/config.php'; 
$seriesId = urldecode(@$_GET["ser"]);
/* query string not correct */
if ($seriesId == "") {
	echo "Series not found.  You did not select a valid series for editing.";
	die;
}
$params = array(&$seriesId);	

/* get series data */
	/* Create the statement. */
	$tsqlProv = "SELECT Series.SeriesTitle, Series.SeriesOpenDate, Series.SeriesStartYear, Series.SeriesEndYear, Series.SeriesDateRangeDescription, Series.SeriesExtentDescription, Series.SeriesArrangement, Series.SeriesRestrictionDescription, Series.SeriesIdentifier, Provenance.ProvenanceName, Provenance.ProvenanceId, CONVERT(VARCHAR, Series.CreatedDate, 101) AS CreatedDate, Series.CreatedBy, CONVERT(VARCHAR, Series.ModifiedDate, 101) AS ModifiedDate, Series.ModifiedBy FROM Provenance INNER JOIN Series ON Provenance.ProvenanceId = Series.ProvenanceId WHERE Series.SeriesId = (?)";

	$getData = sqlsrv_prepare( $conn, $tsqlProv, $params);
	if( $getData === false ) {
		 echo "Error in preparing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	
	
	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{   
	/*echo "Statement executed.\n";*/
	}
	else
	{
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	$rowCount = 0;
	while (sqlsrv_fetch( $getData ))
	{	
		$title = sqlsrv_get_field($getData, 0);
		$opendate = sqlsrv_get_field($getData, 1);
		$startyear = sqlsrv_get_field($getData, 2);
		$endyear = sqlsrv_get_field($getData, 3);
		$daterange = sqlsrv_get_field($getData, 4);
		$extent = sqlsrv_get_field($getData, 5);
		$arrangement = sqlsrv_get_field($getData, 6);
		$restriction = sqlsrv_get_field($getData, 7);	
		$identifier = sqlsrv_get_field($getData, 8);
		$provname = sqlsrv_get_field($getData, 9);
		$provid = sqlsrv_get_field($getData, 10);	
		$createdon = sqlsrv_get_field($getData, 11);
		$createdby = sqlsrv_get_field($getData, 12);
		$modifiedon = sqlsrv_get_field($getData, 13);
		$modifiedby = sqlsrv_get_field($getData, 14);
		$rowCount++;
	}
	
	/* series id in query string is wrong */
	if( $rowCount == 0 ) { 
	echo "Series not found.  You did not select a valid series for editing.<br/><br/><br/><br/>";
	die;
    	}	

//submit form validation
if (isset($_POST['EditSeries'])){	
		//title is mandatory 	
		if (empty($_POST['SeriesTitle'])) {
			$messageSeries = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a Series Title</span>";
			$submitForm = 1;
			}
	
			/*check if this is a new series title or if it as already been created for this provenance*/	
				$serCheck = ltrim(rtrim($_POST['SeriesTitle']));	
				$tsqlSerCheck = "SELECT SeriesTitle FROM Series WHERE ((SeriesTitle = '".$serCheck."') AND (ProvenanceId = ".$provid.") AND (SeriesId <> ".$seriesId."))";				
				
				$getData = sqlsrv_prepare( $conn, $tsqlSerCheck);
				if( $getData === false ) {
					 echo "Error in preparing statement.<br/><br/><br/><br/>\n";
					 die;
				}

				if( sqlsrv_execute( $getData))
				{  } else {
					 echo "Error in executing statement.<br/><br/><br/><br/>\n";
					 die;
				}
				$rowCount = 0;
				while (sqlsrv_fetch( $getData ))
				{	
					$rowCount++;
				}
				
			if ($rowCount > 0) {
				$messageSeries = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">This series title has already been created for this provenance</span>";				
				$submitForm = 1;
			};

//open date		
  	if (!empty($_POST['SeriesOpenDate'])) {
if (!ereg ("([0-3]{1})([0-9]{1})/([0-9]{1,2})/([0-3]{1})([0-9]{3})",$_POST['SeriesOpenDate'])) {		   
		   $messageOpenDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid date. (eg. mm/dd/yyyy)</span>";
		   $submitForm = 1;
			}
			}
//start year	
  	if (!empty($_POST['SeriesStartYear'])) {	
	if (!ereg("([0-9]{4})",$_POST['SeriesStartYear']) || strlen($_POST['SeriesStartYear'])!==4) {	   
		$messageStartDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid year. (eg. yyyy)</span>";
		$submitForm = 1;
		}
		else{
			if($_POST['SeriesStartYear'] < 2100 && $_POST['SeriesStartYear'] >= 1492){}
			else{					
					$messageStartDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid year. (eg. yyyy)</span>";
					$submitForm = 1;
				}
		}
		}
//end year		
  	if (!empty($_POST['SeriesEndYear'])) {
	if (!ereg("([0-9]{4})",$_POST['SeriesEndYear']) || strlen($_POST['SeriesEndYear'])!==4) {
		$messageEndDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid year. (eg. yyyy)</span>";
		$submitForm = 1;
		}
		else{
			if($_POST['SeriesEndYear'] < 2100 && $_POST['SeriesEndYear'] >= 1492){}
			else{					
					$messageEndDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid year. (eg. yyyy)</span>";
					$submitForm = 1;
				}
			}
}
//submit form after successful validation-------------------		
		if (!isset($submitForm)){			
			
			/*Get all the field values from user input*/
				$serTitle = $_POST["SeriesTitle"];
				$serDesc = $_POST["SeriesDescription"];
				$serOpenDate = $_POST["SeriesOpenDate"];
				$serDateRange = $_POST["SeriesDateRangeDescription"];
				if ($_POST["SeriesStartYear"] == "") {
					$serStart = NULL;
				} else {
					$serStart = $_POST["SeriesStartYear"];
				}
				if ($_POST["SeriesEndYear"] == "") {
					$serEnd = NULL;
				} else {
					$serEnd = $_POST["SeriesEndYear"];
				}
				$serIdent = $_POST["SeriesIdentifier"];
				$serArr = $_POST["SeriesArrangement"];
				$serExt = $_POST["SeriesExtentDescription"];
				$serRes = $_POST["SeriesRestrictionDescription"];
				$serNote = $_POST["SeriesGeneralNote"];
				
			//check if is submit extra value
			if (isset($_POST['info_input']) && isset($_POST['data_input'])){
				//$arrayVar = array_combine($_POST["info_input"],$_POST["data_input"]);
				//put data from form to array
				$arraySub = array($_POST["info_input"],$_POST["data_input"]);
				}		 
				
			//get existing subjects
			if (isset($_POST["SubjectQual"]) && isset($_POST["SubjectName"])){
				$arraySubId = $_POST["SubjectId"];
				$arraySubExisting = array_combine($_POST["SubjectQual"],$_POST["SubjectName"]);
				$arrayQual = $_POST["SubjectQual"];
				$arrayName = $_POST["SubjectName"];
				}		
				
			//new locations
			if (isset($_POST["Location_input"])) {
				$arrayLoc = $_POST["Location_input"];
			}
			//existing locations
			if (isset($_POST["LocationName"])) {			
				$arrayLocExisting = $_POST["LocationName"];
				$arrayLocId = $_POST["LocationId"];
				$arrayGeoId = $_POST["GeoLocationId"];
			}
			
			//new keywords
			if (isset($_POST["Keyword_input"])) {
				$arrayKey = $_POST["Keyword_input"];
			}
			//existing keywords
			if (isset($_POST["KeywordName"])) {				
				$arrayKeyExisting = $_POST["KeywordName"];	
				$arrayKeyId = $_POST["KeywordId"];
			}
				
			/*Call the stored procedure that inserts data into the Series table*/
					$tsql_callSP = "{call PAC_UpdateSeries( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"; 
					$params = array(   
   								 array($seriesId, SQLSRV_PARAM_IN),
								 array($serTitle, SQLSRV_PARAM_IN),
								 array($serDesc, SQLSRV_PARAM_IN),  
								 array($serOpenDate, SQLSRV_PARAM_IN),  
								 array($serStart, SQLSRV_PARAM_IN),  
								 array($serEnd, SQLSRV_PARAM_IN),  
								 array($serDateRange, SQLSRV_PARAM_IN),  
								 array($serExt, SQLSRV_PARAM_IN),  
								 array($serArr, SQLSRV_PARAM_IN),  
								 array($serRes, SQLSRV_PARAM_IN),  		
								 array($serNote, SQLSRV_PARAM_IN),  
								 array($serIdent, SQLSRV_PARAM_IN),   
								 array($provid, SQLSRV_PARAM_IN)
							   );  
							   					
					$stmt = sqlsrv_query($conn, $tsql_callSP, $params);
					
				if(!$stmt){
					$SQLmessageError = "The series was not updated due to an error.";			
					$SQLErrorDB = print_r(sqlsrv_errors(),true);
					$SQLErrorDBcheck = 1;
					sqlsrv_close($conn);
					exit;					
					}
					
				
		/*For each row of subjects, call the stored procedure that inserts or updates data into the SeriesSubject table*/
		$tsql_callSP = "{call PAC_UpdateSeriesSubject( ?, ?, ?, ?)}"; 				
				
				//add new subjects
				if (!empty($arraySub)){				
				$myArrayPosition =  0;
					foreach($arraySub[0] as $key) {
					$value = $arraySub[1][$myArrayPosition];
					$myArrayPosition ++;
					$subId = NULL;
								$params = array(   
									 array($subId, SQLSRV_PARAM_IN),
									 array($seriesId, SQLSRV_PARAM_IN),
									 array($key, SQLSRV_PARAM_IN),  
									 array($value, SQLSRV_PARAM_IN) 
								   ); 
								   $stmt = sqlsrv_query( $conn, $tsql_callSP, $params);	
								   if (!$stmt){
										$SQLmessageError = "Series subject(s) were not updated due to an error.";
										$SQLErrorDB = print_r(sqlsrv_errors(),true);
										$SQLErrorDBcheck = 1;
										sqlsrv_close($conn);
										break;
										}	
					}
				}
				
				//edit existing subjects
				$i = 0;
				if (!empty($arraySubExisting)){		
					while ($i < count($arraySubId)) {
						$subQual = $arrayQual[$i];
						$subName = $arrayName[$i];
									$subId = $arraySubId[$i];
									$params = array(   
										 array($subId, SQLSRV_PARAM_IN),
										 array($seriesId, SQLSRV_PARAM_IN),
										 array($subQual, SQLSRV_PARAM_IN),  
										 array($subName, SQLSRV_PARAM_IN) 
									   ); 
									   $stmt = sqlsrv_query( $conn, $tsql_callSP, $params);	
									   
									   if (!$stmt){
											$SQLmessageError = "Series subject(s) were not updated due to an error.";
											$SQLErrorDB = print_r(sqlsrv_errors(),true);
											$SQLErrorDBcheck = 1;
											sqlsrv_close($conn);
											break;
											}	
						 $i++;
						} 
					}

		// For each row of subjects, check mark for deletion field and call the stored procedure that deletes subject from SeriesSubject table
		$tsql_callSP = "{call PAC_DeleteSeriesSubject( ?)}"; 	

				if (!empty($_POST["SubjectDelete"])){
				$arraySubDelete = $_POST["SubjectDelete"];
				foreach ($arraySubDelete as $value) {
								$params = array(   
									array($value, SQLSRV_PARAM_IN) 
								); 
								$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);								
							}		
					}	
										
			/*For each row of locations, call the stored procedure that inserts or updates data into the SeriesLocation table*/
		$tsql_callSP = "{call PAC_UpdateSeriesLocation( ?, ?, ?, ?)}"; 				
				
				//add new locations
				if (!empty($arrayLoc)){	
				$locId = NULL;
				$geoId = NULL;
					foreach ($arrayLoc as $value) {		
								$params = array(   
									 array($locId, SQLSRV_PARAM_IN),
									 array($seriesId, SQLSRV_PARAM_IN),
									 array($geoId, SQLSRV_PARAM_IN),
									 array($value, SQLSRV_PARAM_IN),  
								   ); 
								   $stmt = sqlsrv_query( $conn, $tsql_callSP, $params);	
					}
				}
				
				//edit existing locations
				$i = 0;
				if (!empty($arrayLocExisting)){		
					while ($i < count($arrayLocId)) {
						$locName = $arrayLocExisting[$i];
						$locId = $arrayLocId[$i];
						$geoId = $arrayGeoId[$i];
									$params = array(   
										 array($locId, SQLSRV_PARAM_IN),
										 array($seriesId, SQLSRV_PARAM_IN),
										 array($geoId, SQLSRV_PARAM_IN),
										 array($locName, SQLSRV_PARAM_IN) 
									   ); 
									   $stmt = sqlsrv_query( $conn, $tsql_callSP, $params);	
						 $i++;
						} 
					}

		// For each row of locations, check mark for deletion field and call the stored procedure that deletes locations from SeriesLocation table
		$tsql_callSP = "{call PAC_DeleteSeriesLocation(?)}"; 	

				if (!empty($_POST["LocationDelete"])){
					$arrayLocDelete = $_POST["LocationDelete"];
					foreach ($arrayLocDelete as $value) {
								$params = array(   
									array($value, SQLSRV_PARAM_IN) 
								); 
								$stmt = sqlsrv_query($conn, $tsql_callSP, $params);								
							}		
					}	
					
			/*For each row of keywords, call the stored procedure that inserts or updates data into the SeriesKeyword table*/
		$tsql_callSP = "{call PAC_UpdateSeriesKeyword( ?, ?, ?)}"; 				
				
				//add new locations
				if (!empty($arrayKey)){	
				$keyId = NULL;
					foreach ($arrayKey as $value) {		
								$params = array(   
									 array($keyId, SQLSRV_PARAM_IN),
									 array($seriesId, SQLSRV_PARAM_IN),
									 array($value, SQLSRV_PARAM_IN),  
								   ); 
								   $stmt = sqlsrv_query( $conn, $tsql_callSP, $params);	
					}
				}
				
				//edit existing keywords
				$i = 0;
				if (!empty($arrayKeyExisting)){		
					while ($i < count($arrayKeyId)) {
						$keyName = $arrayKeyExisting[$i];
									$keyId = $arrayKeyId[$i];
									$params = array(   
										 array($keyId, SQLSRV_PARAM_IN),
										 array($seriesId, SQLSRV_PARAM_IN),
										 array($keyName, SQLSRV_PARAM_IN) 
									   ); 
									   $stmt = sqlsrv_query( $conn, $tsql_callSP, $params);	
						 $i++;
						} 
					}

		// For each row of keywords, check mark for deletion field and call the stored procedure that deletes keywords from SeriesKeyword table
		$tsql_callSP = "{call PAC_DeleteSeriesKeyword(?)}"; 	

				if (!empty($_POST["KeywordDelete"])){
					$arrayKeyDelete = $_POST["KeywordDelete"];
					foreach ($arrayKeyDelete as $value) {
								$params = array(   
									array($value, SQLSRV_PARAM_IN) 
								); 
								$stmt = sqlsrv_query($conn, $tsql_callSP, $params);								
							}		
					}	
					
																
			/*Close out the connections*/
			if (!isset($SQLErrorDBcheck)){	
				include("includes/serNewSuccess.php");
				sqlsrv_close($conn);
				exit;
				}
		}
}
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Persistent Digital Archives and Library System" />
<title>PeDALS Web Administration</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="includes/showdesc.js"></script>
</head>
<body>
<?php include 'includes\header.php'; ?>
<script language="javascript">
/*April 1 2009
Function add Element create on-the-fly new DIV switch holds everything that we want to put on our website
Function remove element delete one element from our div
*/
var nextNumber = 0;
function addElement() {
  nextNumber += 1;  
  var newDiv = document.createElement('div');
  var divId = 'input'+nextNumber+'Div';
  newDiv.setAttribute('id',divId);
  newDiv.innerHTML = '<tr><td style=\"padding: 5px;\"><input type=\"text\" name=\"info_input[]\" maxlength=\"50\" size=\"17\"></td><td style=\"padding: 5px;\"><input type=\"text\" name=\"data_input[]\" maxlength=\"100\" size=\"45\"></td><td><a href=\"javascript:;\" onclick=\"removeElement(\''+divId+'\');\" style=\"text-decoration: none;\">&nbsp;<img border=\"0\" src=\"images/delete.png\"/></a></td></tr>'; 
  document.getElementById('contentDiv').appendChild(newDiv);
}
function removeElement(divNum) {
    document.getElementById('contentDiv').removeChild(document.getElementById(divNum));
}


var nextNumberKeyword = 0;
function addElementKeyword() {
  nextNumberKeyword += 1;  
  var newDivKeyword = document.createElement('div');
  var divIdKeyword = 'input'+nextNumberKeyword+'Div';
  newDivKeyword.setAttribute('id',divIdKeyword);
  newDivKeyword.innerHTML = '<tr><td style=\"padding: 5px;\"><input type=\"text\" name=\"Keyword_input[]\" maxlength=\"50\" size=\"70\"></td><td><a href=\"javascript:;\" onclick=\"removeElementKeyword(\''+divIdKeyword+'\');\" style=\"text-decoration: none;\">&nbsp;<img border=\"0\" src=\"images/delete.png\"/></a></td></tr>'; 
  document.getElementById('contentDivKeyword').appendChild(newDivKeyword);
}
function removeElementKeyword(divNumKeyword) {
    document.getElementById('contentDivKeyword').removeChild(document.getElementById(divNumKeyword));
}

var nextNumberLocation = 0;
function addElementLocation() {
  nextNumberLocation += 1;  
  var newDivLocation = document.createElement('div');
  var divIdLocation = 'input'+nextNumberLocation+'Div';
  newDivLocation.setAttribute('id',divIdLocation);
  newDivLocation.innerHTML = '<tr><td style=\"padding: 5px;\"><input type=\"text\" name=\"Location_input[]\" maxlength=\"250\" size=\"70\"></td><td><a href=\"javascript:;\" onclick=\"removeElementLocation(\''+divIdLocation+'\');\" style=\"text-decoration: none;\">&nbsp;<img border=\"0\" src=\"images/delete.png\"/></a></td></tr>'; 
  document.getElementById('contentDivLocation').appendChild(newDivLocation);
}
function removeElementLocation(divNumLocation) {
    document.getElementById('contentDivLocation').removeChild(document.getElementById(divNumLocation));
}
</script>
<div id="breadcrumb-container">
  <div id="breadcrumb"><a href="index.php" title="Home page">Home</a> / <a href="serSummary.php" title="Series">Series</a> / Edit Series</div>
  <div id="breadcrumb-side"><form name="search" action="search.php"><input type="text" name="q" width="50"/><input type="submit" value="Go" /></form><a href="advSearch.php" title="Advanced Search" alt="Advanced Search">Advanced Search</a>
  </div>
  <div class="clear"></div>
</div>
<!-- 

  CONTENT

  -->
<div id="content-container">
  <!-- 
	
	SIDE COLUMN
	
	-->
  <div id="content-side">
    <ul class="link-list-vertical">
      <li><a href="serSummary.php" title="View a list of all series in PeDALS.">List Series</a></li>
      <li><a href="serNew.php" title="Add a new series to PeDALS.">Add Series</a></li>
    </ul>
  </div>
  <!-- 
	
	MAIN COLUMN
	
	-->
  <div id="content"><a name="maincontent" id="maincontent"></a>
    <h1>Edit Series</h1>
    
<?php 
//Error Message Box
if(isset($SQLErrorDB) && isset($SQLmessageError)){
$errorDiv = <<<__HTML_END
    <div style="padding-right:20px; font-size:16px; color:#F00;">$SQLmessageError
    <div style="cursor:pointer; color:#900; font-size: 12px;" onclick="if(document.getElementById('sqlServerErrorMessage').style.display == 'none')document.getElementById('sqlServerErrorMessage').style.display = ''; else document.getElementById('sqlServerErrorMessage').style.display = 'none';">Show error details</div>    
    <div id="sqlServerErrorMessage" style="background-color:#FFFFFF; color:#000; font-family:'Courier New', Courier, monospace; font-size:12px; border:1px solid #F00; width:100%; display:none; padding:7px;">$SQLErrorDB</div>    
    </div>
__HTML_END;
echo $errorDiv;
}
?>
</p>

<!--- Includes for Core Standards --->
<div id="div201" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\201.html'; ?></div>

<div id="div202.1" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\202.1.html'; ?></div>

<div id="div202.2" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\202.2.html'; ?></div>

<div id="div202.3" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\202.3.html'; ?></div>

<div id="div203" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\203.html'; ?></div>

<div id="div204" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\204.html'; ?></div>

<div id="div205" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\205.html'; ?></div>

<div id="div206" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\206.html'; ?></div>

<div id="div207" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\207.html'; ?></div>

<div id="div207.1" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\207.1.html'; ?></div>

<div id="div207.2" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\207.2.html'; ?></div>

<div id="div208" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\208.html'; ?></div>

<div id="div208.1" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\208.1.html'; ?></div>

<div id="div208.2" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\208.2.html'; ?></div>

<div id="div209" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\209.html'; ?></div>

<div id="div210" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\210.html'; ?></div>
<!--- End of Includes for Core Standards --->


<form method="POST"> 
<p><strong>Provenance:</strong> <?php echo $provname; ?></p>   
<p><strong>Series Title (mandatory)</strong> (<a onclick="showhide('div201');" class="desclink">201</a>)
<?php if (isset($messageSeries))echo $messageSeries;?>
<br/><input type="text" name="SeriesTitle" size="90" maxlength="250" value="<?php echo $title; ?>"></p>
<p><strong>Identifier</strong><br/><input type="text" name="SeriesIdentifier" size="90" maxlength="50" value="<?php echo $identifier; ?>"></p> 
<p><strong>Date Range</strong> (<a onclick="showhide('div202.1');" class="desclink">202.1</a>)<br/><input type="text" name="SeriesDateRangeDescription" size="20" maxlength="100" value="<?php echo $daterange; ?>"></p>
<p><strong>Start Year (YYYY)</strong> (<a onclick="showhide('div202.2');" class="desclink">202.2</a>)
<?php if (isset($messageStartDate))echo $messageStartDate;?>
<br/><input type="text" name="SeriesStartYear" size="5" maxlength="4"  value="<?php echo $startyear; ?>"></p>
<p><strong>End Year (YYYY)</strong> (<a onclick="showhide('div202.3');" class="desclink">202.3</a>)
<?php if (isset($messageEndDate))echo $messageEndDate;?>
<br/><input type="text" name="SeriesEndYear" size="5" maxlength="4"  value="<?php echo $endyear; ?>"></p>
<p><strong>Extent Description</strong> (<a onclick="showhide('div203');" class="desclink">203</a>)<br/><textarea name="SeriesExtentDescription" rows="3" cols="68" maxlength="1024"><?php echo $extent; ?></textarea></p>   
<p><strong>Arrangement</strong> (<a onclick="showhide('div204');" class="desclink">204</a>)<br/><textarea name="SeriesArrangement" rows="3" cols="68" maxlength="1024"><?php echo $arrangement; ?></textarea></p> 

<p><strong>Description</strong> (<a onclick="showhide('div205');" class="desclink">205</a>)
<br/><textarea name="SeriesDescription" rows="8" cols="68">
<?php 
$tsqlSD = "SELECT SeriesDescription FROM Series WHERE SeriesId = (?)";
$stmt = sqlsrv_query( $conn, $tsqlSD, $params);

while ($rr=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH)){
	echo $rr[0];
}
 ?>
</textarea></p> 
<p><strong>General Note</strong> (<a onclick="showhide('div206');" class="desclink">206</a>)<br/><textarea name="SeriesGeneralNote" rows="3" cols="68">
<?php 
$tsqlSD = "SELECT SeriesGeneralNote FROM Series WHERE SeriesId = (?)";
$stmt = sqlsrv_query( $conn, $tsqlSD, $params);

while ($rr=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH)){
	echo $rr[0];
}
 ?>
</textarea></p>   
<p><strong>Open Date (MM/DD/YYYY)</strong> (<a onclick="showhide('div207');" class="desclink">207</a>) (<a onclick="showhide('div207.2');" class="desclink">207.2</a>)
<?php if (isset($messageOpenDate))echo $messageOpenDate;?>
<br/><input type="text" name="SeriesOpenDate" size="10" maxlength="50" value="<?php echo $opendate; ?>"></p>
<p><strong>Restriction Description</strong> (<a onclick="showhide('div207.1');" class="desclink">207.1</a>)<br/><input type="text" name="SeriesRestrictionDescription" size="90" maxlength="1024" value="<?php echo $restriction; ?>"></p>      
<br/>
<p><strong>Geographic Locations</strong> (<a onclick="showhide('div209');" class="desclink">209</a>)
        <table class="table" border="1" cellspacing="0" summary="Table listing">
      <thead>
        <tr>
          <th scope="col" width="200px">Location</th>
     	  <th scope="col" width="50px">Mark for Deletion</th>          
        </tr>
      </thead>
      <tbody>
   <?php	
		$tsqlVar = "SELECT SeriesGeoLocation_LINK.SeriesGeoLocationId, GeoLocation.GeoLocationId, GeoLocation.GeoLocationValue FROM  SeriesGeoLocation_LINK INNER JOIN GeoLocation ON SeriesGeoLocation_LINK.GeoLocationId = GeoLocation.GeoLocationId WHERE SeriesGeoLocation_LINK.SeriesId = (?) ORDER BY GeoLocation.GeoLocationValue";
	/* Create the statement. */
	$getData = sqlsrv_prepare( $conn, $tsqlVar, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.\n";
		 die;
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	
	} else {
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	$rowCount = 0;
	
	/* Show list of locations */
	while (sqlsrv_fetch( $getData ))
	{
		$locId = sqlsrv_get_field($getData,0);
		$geoId = sqlsrv_get_field($getData,1);
		$locName = sqlsrv_get_field($getData, 2);
		echo "<tr><td>";
		echo "<input type=\"hidden\" name=\"LocationId[]\" value=\"".$locId."\">";
		echo "<input type=\"hidden\" name=\"GeoLocationId[]\" value=\"".$geoId."\">";
		echo "<input type=\"text\" size=\"75\" maxlength=\"250\" name=\"LocationName[]\" value=\"".$locName."\">";
		echo "</td><td align=\"center\">";
		echo "<input type=\"checkbox\" name=\"LocationDelete[]\" \"unchecked\"  value=\"".$locId."\"></td></tr>";

		$rowCount++;
    }	

	/* If locations are not found */
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\">There are no locations yet.</td></tr>"; 
    	}
	
?>	      
      		<tr><td colspan="2"><a href="javascript: addElementLocation();" style="text-decoration: none; vertical-align: text-middle;"><img border="0" src="images/add.png"/>Add Location</a>
			<div id="contentDivLocation"></div></td></tr>
	</tbody>
	</table>
</p> 
<br/>   
<p><strong>Keywords</strong> (<a onclick="showhide('div210');" class="desclink">210</a>)
        <table class="table" border="1" cellspacing="0" summary="Table listing">
      <thead>
        <tr>
          <th scope="col" width="200">Keyword</th>
     	  <th scope="col" width="50">Mark for Deletion</th>          
        </tr>
      </thead>
      <tbody>
   <?php	
	$tsqlVar = "SELECT SeriesKeywordId, SeriesKeyword FROM SeriesKeyword 
		WHERE SeriesId = (?) ORDER BY SeriesKeyword";   
		
	/* Create the statement. */
	$getData = sqlsrv_prepare( $conn, $tsqlVar, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.\n";
		 die;
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	
	} else {
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	$rowCount = 0;
	
	/* Show list of keywords */
	while (sqlsrv_fetch( $getData ))
	{
		$keyId = sqlsrv_get_field($getData,0);
		$keyName = sqlsrv_get_field($getData, 1);
		echo "<tr><td>";
		echo "<input type=\"hidden\" name=\"KeywordId[]\" value=\"".$keyId."\">";
		echo "<input type=\"text\" size=\"75\" maxlength=\"50\" name=\"KeywordName[]\" value=\"".$keyName."\">";
		echo "</td><td align=\"center\">";
		echo "<input type=\"checkbox\" name=\"KeywordDelete[]\" \"unchecked\"  value=\"".$keyId."\"></td></tr>";

		$rowCount++;
    }	

	/* If keywords are not found */
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\">There are no keywords yet.</td></tr>"; 
    	}
	
?>	      
      		<tr><td colspan="2"><a href="javascript: addElementKeyword();" style="text-decoration: none; vertical-align: text-middle;"><img border="0" src="images/add.png"/>Add Keyword</a>
			<div id="contentDivKeyword"></div></td></tr>
	</tbody>
	</table>
</p> 

<br/>
<p><strong>Subjects</strong> (<a onclick="showhide('div208');" class="desclink">208</a>)</p>
        <table class="table" border="1" cellspacing="0" summary="Table listing">
      <thead>
        <tr>
          <th scope="col" width="100">Subject Qualifier (<a onclick="showhide('div208.1');" class="desclink">208.1</a>)</th>
          <th scope="col" width="250">Subject Heading (<a onclick="showhide('div208.2');" class="desclink">208.2</a>)</th>
     	  <th scope="col" width="50">Mark for Deletion</th>          
        </tr>
      </thead>
      <tbody>
   <?php	
	$tsqlVar = "SELECT SeriesSubject_LINK.SeriesSubjectId, Qualifier.QualifierId, Qualifier.QualifierType, Subject.SubjectName FROM Subject INNER JOIN SeriesSubject_LINK ON Subject.SubjectId = SeriesSubject_LINK.SubjectId INNER JOIN Qualifier ON SeriesSubject_LINK.QualifierId = Qualifier.QualifierId WHERE SeriesSubject_LINK.SeriesId = (?) ORDER BY Qualifier.QualifierType, Subject.SubjectName";	
	
	/* Create the statement. */
	$getData = sqlsrv_prepare( $conn, $tsqlVar, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.\n";
		 die;
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	
	} else {
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	$rowCount = 0;
	
	/* Show list of variant names */
	while (sqlsrv_fetch( $getData ))
	{
		$seriesSubId = sqlsrv_get_field($getData,0);
		$subQualId = sqlsrv_get_field($getData,1);		
		$subQual = sqlsrv_get_field($getData, 2);
		$subName = sqlsrv_get_field($getData, 3);
		echo "<tr><td>";
		echo "<input type=\"hidden\" name=\"SubjectId[]\" value=\"".$seriesSubId."\">";
		echo "<input type=\"hidden\" name=\"SubjectQualId[]\" value=\"".$subQualId."\">";		
		echo "<input type=\"text\" size=\"17\" maxlength=\"50\" name=\"SubjectQual[]\" value=\"".$subQual."\">";
		echo "</td><td>";
		echo "<input type=\"text\" size=\"45\" maxlength=\"100\" name=\"SubjectName[]\" value=\"".$subName."\">";
		echo "</td><td align=\"center\"><input type=\"checkbox\" name=\"SubjectDelete[]\" \"unchecked\"  value=\"".$seriesSubId."\"></td></tr>";

		$rowCount++;
    }	

	/* If subjects are not found */
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\">There are no subjects yet.</td></tr>"; 
    	}
	
?>	      
      		<tr><td colspan="2"><a href="javascript: addElement();" style="text-decoration: none; vertical-align: text-middle;"><img border="0" src="images/add.png"/>Add Subject</a>
			<div id="contentDiv"></div></td></tr>
	</tbody>
	</table>
<br/>   
	  <input type="submit" value="submit" name="EditSeries"><br />
      <input type="hidden" name="_submit_check" value="1"/> 
</form>
<!--Perform the following if user clicks on the submit button-->
<?php
if (array_key_exists('_submit_check', $_POST)) {

}

?>
<?php include 'includes\footer.php'; ?>
</div>
</body>
</html>
